package com.stylefeng.guns.modular.contractmanager.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ContractDetail;
import com.stylefeng.guns.modular.contractmanager.service.IContractDetailService;

/**
 * 合同商品详情控制器
 *
 * @author LiuXin
 * @Date 2018-11-14 10:37:30
 */
@Controller
@RequestMapping("/contractDetail")
public class ContractDetailController extends BaseController {

    private String PREFIX = "/contractmanager/contractDetail/";

    @Autowired
    private IContractDetailService contractDetailService;

    /**
     * 跳转到合同商品详情首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "contractDetail.html";
    }

    /**
     * 跳转到添加合同商品详情
     */
    @RequestMapping("/contractDetail_add")
    public String contractDetailAdd() {
        return PREFIX + "contractDetail_add.html";
    }

    /**
     * 跳转到修改合同商品详情
     */
    @RequestMapping("/contractDetail_update/{contractDetailId}")
    public String contractDetailUpdate(@PathVariable Integer contractDetailId, Model model) {
        ContractDetail contractDetail = contractDetailService.selectById(contractDetailId);
        model.addAttribute("item",contractDetail);
        LogObjectHolder.me().set(contractDetail);
        return PREFIX + "contractDetail_edit.html";
    }

    /**
     * 获取合同商品详情列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return contractDetailService.selectList(null);
    }

    /**
     * 新增合同商品详情
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ContractDetail contractDetail) {
        contractDetailService.insert(contractDetail);
        return SUCCESS_TIP;
    }

    /**
     * 删除合同商品详情
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer contractDetailId) {
        contractDetailService.deleteById(contractDetailId);
        return SUCCESS_TIP;
    }

    /**
     * 修改合同商品详情
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ContractDetail contractDetail) {
        contractDetailService.updateById(contractDetail);
        return SUCCESS_TIP;
    }

    /**
     * 合同商品详情详情
     */
    @RequestMapping(value = "/detail/{contractDetailId}")
    @ResponseBody
    public Object detail(@PathVariable("contractDetailId") Integer contractDetailId) {
        return contractDetailService.selectById(contractDetailId);
    }
}
